package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import coreAlgorithm.ID;
import coreAlgorithm.KeyValueStore;

public class KeyValueStoreTest {
	KeyValueStore kvs;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		kvs = new KeyValueStore();
		kvs.putValue(new ID(1), "One");
		kvs.putValue(new ID(4), "Four");
		kvs.putValue(new ID(2), "Two");
	}

	@Test
	public void testIsKeyStored() {
		assertTrue(kvs.isKeyStored(new ID(4)));
		assertTrue(kvs.isKeyStored(new ID(2)));
		assertTrue(kvs.isKeyStored(new ID(1)));
		assertFalse(kvs.isKeyStored(new ID(5)));
	}

	@Test
	public void testGetValue() {
		assertEquals("Four", kvs.getValue(new ID(4)));
		assertEquals("One", kvs.getValue(new ID(1)));
		assertEquals("Two", kvs.getValue(new ID(2)));
		assertNull(kvs.getValue(new ID(15)));
	}

	@Test
	public void testPutValue() {
		assertFalse(kvs.isKeyStored(new ID(7)));
		kvs.putValue(new ID(7), "Seven");
		assertTrue(kvs.isKeyStored(new ID(7)));
		kvs.putValue(new ID(7), "NewSeven");
		assertEquals("NewSeven", kvs.getValue(new ID(7)));
	}

}
